home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / gemtrm12.zoo / txtwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  21.9 KB  |  915 lines

  1. /*********************************************************************
  2.  * GEMTERM V1.2
  3.  * 1992 by Martin F. Gergeleit
  4.  * placed in the public domain
  5.  *
  6.  * GEMTERM COMES WITH ABSOLUTELY NO WARRANTY, NOR WILL I BE LIABLE FOR ANY
  7.  * DAMAGES INCURRED FROM THE USE OF IT. USE ENTIRELY AT YOUR OWN RISK!!!
  8.  *********************************************************************/
  9.  
  10. #include <gemfast.h>
  11. #include <osbind.h>
  12. #include <mintbind.h>
  13. #include <filesys.h>
  14. #include <basepage.h>
  15. #include "txtwin.h"
  16.  
  17. #ifdef DEBUG
  18. #include <stdio.h>
  19. #endif
  20.  
  21. extern int   gl_hchar;
  22. extern int   gl_wchar;
  23. extern int   gl_wbox;
  24. extern int   gl_hbox; /* system sizes */
  25.  
  26. extern int   xdesk,ydesk,hdesk,wdesk;
  27. extern int   handle;
  28. extern int   tty;
  29. extern short tty_used;
  30.  
  31. static int   start_pos = 5;
  32. static char  mem_txt[] = "[0][Not enough memory ][Hmm]";
  33.  
  34. int   ret;
  35.  
  36. init_txt_win(win, font, height)
  37. txt_win *win;
  38. int font, height;
  39.  
  40. {
  41. int   i;
  42. int   tmpx, tmpy, tmpw, tmph;
  43.  
  44. #ifdef DEBUG
  45.        fprintf(stderr, "init_txt_win starts\n");
  46. #endif
  47.  
  48.   win->wtext = (char *)malloc(win->lines * (win->cols+1));
  49.   if (win->wtext == 0) {
  50.     form_alert(1, mem_txt);
  51.     return;
  52.   }
  53.   win->attr = (char *)malloc(win->lines * win->cols);
  54.   if (win->attr == 0) {
  55.     free(win->wtext);
  56.     win->wtext = 0;
  57.     form_alert(1, mem_txt);
  58.     return;
  59.   }
  60.   for (i = 0; i < win->lines; i++)
  61.     win->wtext[i * (win->cols+1)] = '\0';
  62.  
  63.   win->font = font;
  64.   win->height = height;
  65.   vst_font(handle, win->font);
  66.   vst_point(handle, win->height, &ret,&ret,&win->c_width,&win->c_height);
  67. #ifdef DEBUG
  68.   fprintf(stderr, "fonts initialized\n");
  69. #endif
  70.  
  71.   win->xwork = xdesk;
  72.   win->ywork = ydesk;
  73.   win->wwork = win->cols * win->c_width;
  74.   win->hwork = win->lines * win->c_height;
  75.  
  76.   win->hs_s = 0;
  77.   win->hs_p = 0;
  78.   win->vs_s = 0;
  79.   win->vs_p = 0;
  80.  
  81.   win->x_start = 0;
  82.   win->y_start = win->lines - 1;
  83.   win->x_cursor = 0;
  84.   win->y_cursor = 0;
  85.   win->esc = 0;
  86.   win->wrap_line = TRUE;
  87.   win->reverse_video = FALSE;
  88.   win->cursor_enabled = TRUE;
  89.   win->x_save = 0;
  90.   win->y_save = 0;
  91.  
  92.   win->hist_in = 0;
  93.   win->history = (char *)malloc(win->hist_size);
  94.   win->hist_out = win->hist_size-1;
  95.   win->history[win->hist_out] = '\0';
  96.   win->lines_written = 0;
  97.   win->last_out = win->hist_size + 1;
  98.  
  99.   win->status = UNSHOWN;
  100.   win->fulled = FALSE;
  101.  
  102.   win->pid = NO_PID;
  103.  
  104.   wind_calc(1, WI_KIND, xdesk+start_pos, ydesk+start_pos, wdesk-start_pos,
  105.       hdesk-start_pos, &win->xwork, &win->ywork, &win->wwork,
  106.       &win->hwork);
  107.   start_pos = (start_pos + 10) % 40;
  108.  
  109.   if ((win->cols * win->c_width) < win->wwork)
  110.     win->wwork = win->cols * win->c_width;
  111.   if ((win->lines * win->c_height) < win->hwork)
  112.     win->hwork = win->lines * win->c_height;
  113.   win->hwork = (win->hwork / win->c_height) * win->c_height;
  114.   wind_calc(0, WI_KIND, win->xwork, win->ywork, win->wwork, win->hwork,
  115.       &tmpx, &tmpy, &tmpw, &tmph);
  116.  
  117. #ifdef DEBUG
  118.   fprintf(stderr, "init_txt_window ends\n");
  119. #endif
  120. }
  121.  
  122. update_txt_win(win)
  123. txt_win *win;
  124. {
  125. int i;
  126. char c;
  127. int cursor_hop;
  128. int linecount = 5;
  129.  
  130. #ifdef DEBUG
  131.   fprintf(stderr, "update_txt_window starts\n");
  132. #endif
  133.  
  134.   if (win->status == OPEN) {
  135.     vst_font(handle, win->font);
  136.     vst_point(handle, win->height, &ret,&ret,&ret,&ret);
  137.  
  138.     graf_mouse(M_OFF,0x0L);
  139.     wind_update(TRUE);
  140.   }
  141.  
  142.   cursor(win, FALSE);
  143.  
  144.   while ((Finstat(win->real_pty)) && (linecount > 0)) {
  145.    cursor_hop = FALSE;
  146.    c = (char)Fgetchar(win->real_pty,0);
  147.  
  148. #ifdef DEBUG
  149.   fprintf(stderr, "got char: %x\n", c);
  150. #endif
  151.  
  152.    if (win->y_start + 1 < win->hwork/win->c_height) {
  153.      win->y_start = win->lines - 1;
  154.      do_wm_redraw(win);
  155.      update_slider(win);
  156.    }
  157.  
  158.    if (win->esc == 5) {
  159.     /* Background Color */
  160.     win->esc = 0;
  161.    }
  162.    else if (win->esc == 4) {
  163.     /* Foreground Color */
  164.     win->esc = 0;
  165.    }
  166.    else if (win->esc == 2) {
  167.     win->y_cursor = (short)c - ' ';
  168.     if (win->y_cursor >= win->lines)
  169.       win->y_cursor = win->lines-1;
  170.     win->esc = 3;
  171.    }
  172.    else if (win->esc == 3) {
  173.     win->x_cursor = (short)c - ' ';
  174.     if (win->x_cursor >= win->cols)
  175.       win->x_cursor = win->cols-1;
  176.     cursor_hop = TRUE;
  177.     win->esc = 0;
  178.    }
  179.    else if (win->esc == 1) {
  180.     win->esc = 0;
  181.     switch (c) {
  182.     case 'A':
  183.       if (win->y_cursor > 0)
  184.         win->y_cursor--;
  185.       cursor_hop = TRUE;
  186.       break;
  187.     case 'B':
  188.       if (win->y_cursor < win->lines)
  189.         win->y_cursor++;
  190.       cursor_hop = TRUE;
  191.       break;
  192.     case 'C':
  193.       if (win->x_cursor < win->cols)
  194.         win->x_cursor++;
  195.       cursor_hop = TRUE;
  196.       break;
  197.     case 'D':
  198.       if (win->x_cursor > 0)
  199.         win->x_cursor--;
  200.       break;
  201.     case 'E':
  202.       win->x_cursor = 0;
  203.       win->y_cursor = 0;
  204.       for (i = 0; i < win->lines; i++)
  205.         win->wtext[i * (win->cols+1)] = '\0';
  206.       clear_area(win, 0, 0, win->cols-1, win->lines-1);
  207.      break;
  208.     case 'H':
  209.       win->x_cursor = 0;
  210.       win->y_cursor = 0;
  211.       break;
  212.     case 'I':
  213.       if (win->y_cursor != 0)
  214.         win->y_cursor--;
  215.       else {
  216.         for (i = win->lines - 1; i > 0; i--) {
  217.           strcpy(&win->wtext[i*(win->cols+1)], &win->wtext[(i-1)*(win->cols+1)]);
  218.           bcopy(&win->attr[(i-1)*win->cols], &win->attr[i*win->cols], win->cols);
  219.         }
  220.         win->wtext[0] = '\0';
  221.     do_wm_redraw(win);
  222.       }
  223.       cursor_hop = TRUE;
  224.       break;
  225.     case 'J':
  226.       clear_area(win, win->x_cursor, win->y_cursor, win->cols-1, win->y_cursor);
  227.       clear_area(win, 0, win->y_cursor+1, win->cols-1, win->lines-1);
  228.       win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor] = '\0';
  229.       for (i = win->y_cursor + 1; i < win->lines; i++)
  230.         win->wtext[i* (win->cols+1)] = '\0';
  231.       break;
  232.     case 'K':
  233.       clear_area(win, win->x_cursor, win->y_cursor, win->cols-1, win->y_cursor);
  234.       win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor] = '\0';
  235.       break;
  236.     case 'L':
  237.       for (i = win->lines - 1; i > win->y_cursor; i--) {
  238.         strcpy(&win->wtext[i*(win->cols+1)], &win->wtext[(i-1)*(win->cols+1)]);
  239.         bcopy(&win->attr[(i-1)*win->cols], &win->attr[i*win->cols], win->cols);
  240.       }
  241.       win->x_cursor = 0;
  242.       win->wtext[win->y_cursor* (win->cols+1)] = '\0';
  243.       do_wm_redraw(win);
  244.       break;
  245.     case 'M':
  246.       for (i = win->y_cursor + 1; i < win->lines; i++) {
  247.         strcpy(&win->wtext[(i-1)*(win->cols+1)], &win->wtext[i*(win->cols+1)]);
  248.         bcopy(&win->attr[i*win->cols], &win->attr[(i-1)*(win->cols+1)], win->cols);
  249.       }
  250.       win->x_cursor = 0;
  251.       win->wtext[(win->lines-1) * (win->cols+1)] = '\0';
  252.       do_wm_redraw(win);
  253.       break;
  254.     case 'Y':
  255.       win->esc = 2;
  256.       break;
  257.     case 'b':
  258.       win->esc = 4;
  259.       break;
  260.     case 'c':
  261.       win->esc = 5;
  262.       break;
  263.     case 'd':
  264.       clear_area(win, 0, 0, win->cols-1, win->y_cursor-1);
  265.       clear_area(win, 0, win->y_cursor, win->x_cursor, win->y_cursor);
  266.       for (i = 0 ; i <= win->y_cursor; i++)
  267.         win->wtext[win->y_cursor * (win->cols+1)] = '\0';
  268.       for (i = 0 ; i <= win->x_cursor; i++)
  269.         win->wtext[win->y_cursor* (win->cols+1) + i] = ' ';
  270.       break;
  271.     case 'e':
  272.       win->cursor_enabled = TRUE;
  273.       break;
  274.     case 'f':
  275.       win->cursor_enabled = FALSE;
  276.       break;
  277.     case 'j':
  278.       win->x_save = win->x_cursor;
  279.       win->y_save = win->y_cursor;
  280.       break;
  281.     case 'k':
  282.       win->x_cursor = win->x_save;
  283.       win->y_cursor = win->y_save;
  284.       cursor_hop = TRUE;
  285.       break;
  286.     case 'l':
  287.       clear_area(win, 0, win->y_cursor, win->cols-1, win->y_cursor);
  288.       win->x_cursor = 0;
  289.       win->wtext[win->y_cursor* (win->cols+1)] = '\0';
  290.       break;
  291.     case 'o':
  292.       clear_area(win, 0, win->y_cursor, win->x_cursor, win->y_cursor);
  293.       for (i = 0 ; i <= win->x_cursor; i++)
  294.         win->wtext[win->y_cursor* (win->cols+1) + i] = ' ';
  295.       break;
  296.     case 'p':
  297.       win->reverse_video = TRUE;
  298.       break;
  299.     case 'q':
  300.       win->reverse_video = FALSE;
  301.       break;
  302.     case 'v':
  303.       win->wrap_line = TRUE;
  304.       break;
  305.     case 'w':
  306.       win->wrap_line = FALSE;
  307.       break;
  308.     }
  309.    }
  310.    else
  311.     switch (c) {
  312.     case 7:
  313.       Bconout(2,7);
  314.       break;
  315.     case 8:
  316.       if (win->x_cursor > 0)
  317.         win->x_cursor--;
  318.       break;
  319.     case 0x1b:
  320.       win->esc = 1;
  321.       break;
  322.     case 13:
  323.       win->x_cursor=0;
  324.       linecount--;
  325.       break;
  326.     case 10:
  327.       win->y_cursor++;
  328.       cursor_hop = TRUE;
  329.       break;
  330.     case '\t':
  331.       win->x_cursor += TABSTEP - win->x_cursor % TABSTEP;
  332.       cursor_hop = TRUE;
  333.       break;
  334.     default:
  335.       if (c >= ' ') {
  336.     buff_print_at(win, win->x_cursor, win->y_cursor,c,win->reverse_video);
  337.     win->attr[win->y_cursor * win->cols + win->x_cursor] = win->reverse_video;
  338.  
  339.         if (win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor] == '\0') {
  340.           win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor++] = c;
  341.           win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor] = '\0';
  342.         }
  343.         else {
  344.           win->wtext[win->y_cursor* (win->cols+1) + win->x_cursor++] = c;
  345.         }
  346.       }
  347.       break;
  348.     }
  349.  
  350.    if (cursor_hop)
  351.      for (i = 0; (i < win->x_cursor) && (i < win->cols); i++)
  352.        if (win->wtext[win->y_cursor* (win->cols+1) + i] == '\0') {
  353.          win->wtext[win->y_cursor* (win->cols+1) + i] = ' ';
  354.          win->attr[win->y_cursor* win->cols + i] = 
  355.          (c == '\t') ? win->reverse_video : FALSE;
  356.          win->wtext[win->y_cursor* (win->cols+1) + i+1] = '\0';
  357.      }
  358.  
  359.    if (win->x_cursor >= win->cols)
  360.      if (win->wrap_line) {
  361.        win->x_cursor = 0;
  362.        win->y_cursor++;
  363.      } else
  364.        win->x_cursor = win->cols;
  365.  
  366.    if (win->y_cursor >= win->lines) {
  367.      if (win->history != 0)
  368.        put_in_hist(win, &win->wtext[0]);
  369.  
  370.      for (i=1; i < win->lines; i++) {
  371.        strcpy(&win->wtext[(i-1)*(win->cols+1)], &win->wtext[i*(win->cols+1)]);
  372.        bcopy(&win->attr[i*win->cols], &win->attr[(i-1)*win->cols], win->cols);
  373.      }
  374.  
  375.      win->y_cursor = win->lines - 1;
  376.      win->wtext[(win->lines-1) * (win->cols+1)] = '\0';
  377.  
  378.      scroll_screen(win, 1);
  379.    }
  380.   }
  381.  
  382.   flush_buff(win);
  383.   if (win->history != 0)
  384.     update_slider(win);
  385.   cursor(win, TRUE);
  386.  
  387.   if (win->status == OPEN) {
  388.     wind_update(FALSE);
  389.     graf_mouse(M_ON,0x0L);
  390.   }
  391.  
  392. #ifdef DEBUG
  393.   fprintf(stderr, "update_txt_window ends\n");
  394. #endif
  395. }
  396.  
  397. redraw_txt_win(win, rect)
  398. txt_win *win;
  399. GRECT *rect;
  400. {
  401. int ret;
  402.  
  403. #ifdef DEBUG
  404.   fprintf(stderr, "redraw_txt_window starts\n");
  405. #endif
  406.  
  407.   vst_font(handle, win->font);
  408.   vst_point(handle, win->height, &ret,&ret,&ret,&ret);
  409.  
  410.   graf_mouse(M_OFF,0x0L);
  411.  
  412.   redraw_screen(win, rect);
  413.  
  414.   graf_mouse(M_ON,0x0L);
  415.  
  416. #ifdef DEBUG
  417.   fprintf(stderr, "redraw_txt_window ends\n");
  418. #endif
  419. }
  420.  
  421. open_txt_win(win)
  422. txt_win *win;
  423. {
  424. int   tmpx, tmpy, tmpw, tmph;
  425.  
  426. #ifdef DEBUG
  427.   fprintf(stderr, "open_txt_window starts\n");
  428. #endif
  429.  
  430.   win->handle=wind_create(WI_KIND,tmpx,tmpy,tmpw,tmph);
  431.   if (win->handle <= 0) {
  432.     form_alert(1,"[0][No more windows ][Hmm]");
  433.     win->status = UNSHOWN;
  434.     return;
  435.   }
  436.  
  437.   wind_set(win->handle, WF_NAME,win->window_name,0,0,0);
  438. #ifdef DEBUG
  439.   fprintf(stderr, "window name set\n");
  440. #endif
  441.   
  442.   win->vs_s = 0;
  443.   win->vs_p = 0;
  444.   win->hs_s = 0;
  445.   win->hs_p = 0;
  446.  
  447.   wind_calc(0, WI_KIND, win->xwork, win->ywork, win->wwork, win->hwork,
  448.       &tmpx, &tmpy, &tmpw, &tmph);
  449.   if (win->status != TO_BE_REOPEND)
  450.     graf_growbox(tmpx+tmpw/2,tmpy+tmph/2,gl_wbox,gl_hbox,tmpx,tmpy,tmpw,tmph);
  451.   wind_open(win->handle,tmpx,tmpy,tmpw,tmph);
  452. #ifdef DEBUG
  453.   fprintf(stderr, "window opend\n");
  454. #endif
  455.   
  456.   win->status = OPEN;
  457.   update_slider(win);
  458.  
  459. #ifdef DEBUG
  460.   fprintf(stderr, "open_txt_win ends\n");
  461. #endif
  462. }
  463.  
  464. close_txt_win(win)
  465. txt_win *win;
  466. {
  467. int   tmpx, tmpy, tmpw, tmph;
  468.  
  469. #ifdef DEBUG
  470.   fprintf(stderr, "close_txt_win starts\n");
  471. #endif
  472.  
  473.   wind_calc(0, WI_KIND, win->xwork, win->ywork, win->wwork, win->hwork,
  474.       &tmpx, &tmpy, &tmpw, &tmph);
  475.   wind_close(win->handle);
  476.   graf_shrinkbox(tmpx+tmpw/2,tmpy+tmph/2,gl_wbox,gl_hbox,tmpx,tmpy,tmpw,tmph);
  477.   wind_delete(win->handle);
  478.   win->status = UNSHOWN;
  479.  
  480. #ifdef DEBUG
  481.   fprintf(stderr, "close_txt_win ends\n");
  482. #endif
  483. }
  484.  
  485. destroy_txt_win(win)
  486. txt_win *win;
  487. {
  488. #ifdef DEBUG
  489.   fprintf(stderr, "destroy_txt_win starts\n");
  490. #endif
  491.  
  492.   close_txt_win(win);
  493.   free(win->wtext);
  494.   free(win->attr);
  495.   if (win->history != 0)
  496.     free(win->history);
  497.   win->status = CLOSED;
  498.  
  499. #ifdef DEBUG
  500.   fprintf(stderr, "destroy_txt_win ends\n");
  501. #endif
  502. }
  503.  
  504. size_txt_win(win, x, y, w, h)
  505. txt_win *win;
  506. int   x, y, w, h;
  507. {
  508. short smaller = FALSE;
  509.  
  510. #ifdef DEBUG
  511.   fprintf(stderr, "size_txt_win starts\n");
  512. #endif
  513.  
  514.   if(w < MIN_WIDTH)
  515.     w = MIN_WIDTH;
  516.   if(h < MIN_HEIGHT)
  517.     h = MIN_HEIGHT;
  518.  
  519.   if ((w < win->wwork) || (h < win->hwork))
  520.     smaller = TRUE;
  521.  
  522.   wind_calc(WC_WORK,WI_KIND,x,y,w,h,
  523.       &win->xwork,&win->ywork,&win->wwork,&win->hwork);
  524.   if ((win->cols * win->c_width) < win->wwork)
  525.       win->wwork = win->cols * win->c_width;
  526.   if ((win->lines * win->c_height) < win->hwork)
  527.       win->hwork = win->lines * win->c_height;
  528.  
  529.   win->hwork = (win->hwork / win->c_height) * win->c_height;
  530.   win->wwork = (win->wwork / win->c_width) * win->c_width;
  531.  
  532.   if ((win->x_start + win->wwork/win->c_width) > win->cols)
  533.     win->x_start = win->cols - win->wwork/win->c_width;
  534.   if (win->y_start + 1 + win->lines_written < win->hwork/win->c_height)
  535.     win->y_start = (win->hwork/win->c_height) - win->lines_written - 1 ;
  536.  
  537.   wind_calc(0, WI_KIND, win->xwork, win->ywork, win->wwork, win->hwork,
  538.             &x, &y, &w, &h);
  539.   wind_set(win->handle,WF_CURRXYWH,x,y,w,h);
  540.   win->fulled = FALSE;
  541.  
  542.   update_slider(win);
  543.   if (smaller)
  544.     do_wm_redraw(win);
  545.  
  546. #ifdef DEBUG
  547.   fprintf(stderr, "size_txt_win ends\n");
  548. #endif
  549. }
  550.  
  551. full_txt_win(win)
  552. txt_win *win;
  553. {
  554. int   tmpx, tmpy, tmpw, tmph;
  555.  
  556. #ifdef DEBUG
  557.   fprintf(stderr, "full_txt_win starts\n");
  558. #endif
  559.  
  560.   if(win->fulled){
  561.     wind_calc(WC_WORK,WI_KIND,win->xold,win->yold,win->wold,win->hold,
  562.       &win->xwork,&win->ywork,&win->wwork,&win->hwork);
  563.     wind_set(win->handle,WF_CURRXYWH,win->xold,win->yold,win->wold,win->hold);
  564.   }
  565.   else{
  566.     wind_calc(WC_BORDER,WI_KIND,win->xwork,win->ywork,win->wwork,win->hwork,
  567.       &win->xold,&win->yold,&win->wold,&win->hold);
  568.  
  569.     win->wwork = win->cols * win->c_width;
  570.     win->hwork = win->lines * win->c_height;
  571.     wind_calc(0, WI_KIND, win->xwork, win->ywork, win->wwork, win->hwork,
  572.             &tmpx, &tmpy, &tmpw, &tmph);
  573.     wind_set(win->handle,WF_CURRXYWH,tmpx,tmpy,tmpw,tmph);
  574.   }
  575.   win->fulled ^= TRUE;
  576.  
  577.   win->x_start = 0;
  578.   win->y_start = win->lines - 1;
  579.   do_wm_redraw(win);
  580.   update_slider(win);
  581.  
  582. #ifdef DEBUG
  583.   fprintf(stderr, "full_txt_win ends\n");
  584. #endif
  585. }
  586.  
  587. top_txt_win(win)
  588. txt_win *win;
  589. {
  590. #ifdef DEBUG
  591.   fprintf(stderr, "top_txt_win starts\n");
  592. #endif
  593.  
  594.   wind_set(win->handle,WF_TOP,0,0,0,0);
  595.  
  596. #ifdef DEBUG
  597.   fprintf(stderr, "top_txt_win ends\n");
  598. #endif
  599. }
  600.  
  601. arrow_txt_win(win, arrow)
  602. txt_win *win;
  603. int   arrow;
  604. {
  605. GRECT win_rect;
  606.  
  607. #ifdef DEBUG
  608.   fprintf(stderr, "arrow_txt_win starts\n");
  609. #endif
  610.  
  611.   switch (arrow) {
  612.     case WA_UPPAGE:
  613.       win->y_start -= win->hwork/win->c_height;
  614.       break;
  615.     case WA_DNPAGE:
  616.       win->y_start += win->hwork/win->c_height;
  617.       break;
  618.     case WA_UPLINE:
  619.       win->y_start--;
  620.       break;
  621.     case WA_DNLINE:
  622.       win->y_start++;
  623.       break;
  624.     case WA_LFPAGE:
  625.       win->x_start -= win->wwork/win->c_width;
  626.       break;
  627.     case WA_RTPAGE:
  628.       win->x_start += win->wwork/win->c_width;
  629.       break;
  630.     case WA_LFLINE:
  631.       win->x_start--;
  632.       break;
  633.     case WA_RTLINE:
  634.       win->x_start++;
  635.       break;
  636.     default:
  637.       break;
  638.   }
  639.  
  640.   if (win->y_start >= win->lines)
  641.     win->y_start = win->lines-1;
  642.   if (- win->y_start > win->lines_written + 1 - (win->hwork/win->c_height))
  643.     win->y_start = (win->hwork/win->c_height) - win->lines_written - 1 ;
  644.  
  645.   if (win->x_start < 0)
  646.     win->x_start = 0;
  647.   if ((win->x_start + win->wwork/win->c_width) > win->cols)
  648.     win->x_start = win->cols - win->wwork/win->c_width;
  649.  
  650.   update_slider(win);
  651. /*  do_wm_redraw(win); */
  652.  
  653.   win_rect.g_x = win->xwork;
  654.   win_rect.g_y = win->ywork;
  655.   win_rect.g_w = win->wwork;
  656.   win_rect.g_h = win->hwork;
  657.   redraw_txt_win(win, &win_rect);
  658.  
  659. #ifdef DEBUG
  660.   fprintf(stderr, "arrow_txt_win ends\n");
  661. #endif
  662. }
  663.  
  664. hslid_txt_win(win, pos)
  665. txt_win *win;
  666. int   pos;
  667. {
  668. #ifdef DEBUG
  669.   fprintf(stderr, "hslid_txt_win starts\n");
  670. #endif
  671.  
  672.   win->x_start = pos * (win->cols-win->wwork/win->c_width) / 1000;
  673.  
  674.   update_slider(win);
  675.   do_wm_redraw(win);
  676.  
  677. #ifdef DEBUG
  678.   fprintf(stderr, "hslid_txt_win ends\n");
  679. #endif
  680. }
  681.  
  682. vslid_txt_win(win, pos)
  683. txt_win *win;
  684. int   pos;
  685. {
  686. #ifdef DEBUG 
  687.   fprintf(stderr, "vslid_txt_win starts\n");
  688. #endif
  689.   
  690.   win->y_start = pos*(win->lines_written + win->lines - win->hwork/win->c_height) /
  691.       1000 - win->lines_written + win->hwork/win->c_height - 1;
  692.  
  693.   update_slider(win);
  694.   do_wm_redraw(win);
  695.  
  696. #ifdef DEBUG 
  697.   fprintf(stderr, "vslid_txt_win ends\n");
  698. #endif
  699. }
  700.  
  701. mouse_txt_win(win, x, y, n)
  702. txt_win *win;
  703. short   x, y, n;
  704. {
  705. GRECT mouse_rect, win_rect;
  706. int rw, rh, tx1, ty1, tx2, ty2;
  707.  
  708. #ifdef DEBUG 
  709.   fprintf(stderr, "mouse_txt_win starts\n");
  710. #endif
  711.  
  712.   if (win->status != OPEN)
  713.     return;
  714.  
  715.   win_rect.g_x = win->xwork;
  716.   win_rect.g_y = win->ywork;
  717.   win_rect.g_w = win->wwork;
  718.   win_rect.g_h = win->hwork;
  719.  
  720.   mouse_rect.g_x = x;
  721.   mouse_rect.g_y = y;
  722.   mouse_rect.g_w = 1;
  723.   mouse_rect.g_h = 1;
  724.   
  725.   if (rc_intersect(&win_rect, &mouse_rect)) {
  726.     mouse_rect.g_x = x;
  727.     mouse_rect.g_y = y;
  728.     graf_rubberbox(x, y, win->xwork-x-1, win->ywork-y-1,
  729.                     &mouse_rect.g_w, &mouse_rect.g_h);
  730.     rc_intersect(&win_rect, &mouse_rect);
  731.  
  732.     screen2txt(win, x, y, &tx1, &ty1);
  733.     screen2txt(win, x+mouse_rect.g_w, y+mouse_rect.g_h, &tx2, &ty2);
  734.     copy_to_scrapbuf(win, tx1, ty1, tx2, ty2);
  735.   }
  736.  
  737. #ifdef DEBUG 
  738.   fprintf(stderr, "mouse_txt_win ends\n");
  739. #endif
  740. }
  741.  
  742. write_txt_win(win, fd)
  743. txt_win *win;
  744. int   fd;
  745. {
  746. #ifdef DEBUG 
  747.   fprintf(stderr, "write_txt_win starts\n");
  748. #endif
  749.  
  750.   Fwrite(fd, sizeof(txt_win), (char *)win);
  751.  
  752. #ifdef DEBUG 
  753.   fprintf(stderr, "write_txt_win ends\n");
  754. #endif
  755. }
  756.  
  757. read_txt_win(win, fd)
  758. txt_win *win;
  759. int   fd;
  760. {
  761. int   i;
  762. txt_win buffer;
  763. struct winsize wsize;
  764.  
  765. #ifdef DEBUG 
  766.   fprintf(stderr, "read_txt_win starts\n");
  767. #endif
  768.  
  769.   if(Fread(fd, sizeof(txt_win), (char *)&buffer) <= 0)
  770.     return;
  771.  
  772.   win->lines = buffer.lines;
  773.   win->cols = buffer.cols;
  774.   win->wtext = (char *)malloc(win->lines * (win->cols+1));
  775.   if (win->wtext == 0) {
  776.     form_alert(1, mem_txt);
  777.     return;
  778.   }
  779.   win->attr = (char *)malloc(win->lines * win->cols);
  780.   if (win->attr == 0) {
  781.     free(win->wtext);
  782.     win->wtext = 0;
  783.     form_alert(1, mem_txt);
  784.     return;
  785.   }
  786.   for (i = 0; i < win->lines; i++)
  787.     win->wtext[i * (win->cols+1)] = '\0';
  788.  
  789.   win->font = buffer.font;
  790.   win->height = buffer.height;
  791.   vst_font(handle, win->font);
  792.   vst_point(handle, win->height, &ret,&ret,&win->c_width,&win->c_height);
  793.  
  794.   win->xwork = buffer.xwork;
  795.   win->ywork = buffer.ywork;
  796.   win->wwork = buffer.wwork;
  797.   win->hwork = buffer.hwork;
  798.  
  799.   win->hs_s = 0;
  800.   win->hs_p = 0;
  801.   win->vs_s = 0;
  802.   win->vs_p = 0;
  803.  
  804.   win->x_start = 0;
  805.   win->y_start = win->lines - 1;
  806.   win->x_cursor = 0;
  807.   win->y_cursor = 0;
  808.   win->esc = 0;
  809.   win->wrap_line = buffer.wrap_line;
  810.   win->reverse_video = FALSE;
  811.   win->cursor_enabled = TRUE;
  812.   win->x_save = 0;
  813.   win->y_save = 0;
  814.   win->persistent = buffer.persistent;
  815.  
  816.   win->hist_size = buffer.hist_size;
  817.   win->hist_in = 0;
  818.   win->history = (char *)malloc(win->hist_size);
  819.   win->hist_out = win->hist_size-1;
  820.   win->history[win->hist_out] = '\0';
  821.   win->lines_written = 0;
  822.   win->last_out = win->hist_size + 1;
  823.  
  824.   win->status = UNSHOWN;
  825.   win->fulled = FALSE;
  826.  
  827.   win->backslash_conv = buffer.backslash_conv;
  828.   win->keep_on_exit = buffer.keep_on_exit;
  829.  
  830.   strcpy(win->window_name, buffer.window_name);
  831.   strcpy(win->my_args, buffer.my_args);
  832.  
  833.   strcpy(win->cwdir, buffer.cwdir);
  834.  
  835.   wsize.ws_row = win->lines;
  836.   wsize.ws_col = win->cols;
  837.   wsize.ws_xpixel = win->cols * win->c_width;
  838.   wsize.ws_ypixel = win->lines * win->c_height;
  839.   Fcntl(win->real_pty, &wsize, TIOCSWINSZ);
  840.  
  841.   win->real_pty = win->my_pty;
  842.   if (buffer.real_pty != buffer.my_pty)    {    /* so it must have been tty ! */
  843.     if (!tty_used) {
  844.       win->real_pty = tty;
  845.       tty_used = TRUE;
  846.     }
  847.     else 
  848.       return;
  849.   }
  850.  
  851.   open_txt_win(win);
  852.   if (win->status != OPEN) {
  853.     win->status = CLOSED;
  854.     return;
  855.   }
  856.  
  857.   do_av_accwindopen(win->handle);
  858.  
  859.   if (win->real_pty == tty)
  860.     return;
  861.  
  862.   {
  863.   int f0, f1, f2, fm1, client_pty;
  864.   int savedrive;
  865.   char savedir[PATHLEN];
  866.  
  867.      client_pty = Fopen(win->my_pty_name, 2);
  868.      if (client_pty < 0) {
  869.        form_alert(1,"[0][Can not open client pty ][Hmm]");
  870.      }
  871.      else {           
  872.        f0 = Fdup(0);
  873.        Fforce(0, client_pty);
  874.        f1 = Fdup(1);
  875.        Fforce(1, client_pty);
  876.        f2 = Fdup(2);
  877.        Fforce(2, client_pty);
  878.        fm1 = Fdup(-1);
  879.        Fforce(-1, client_pty);
  880.        Fclose(client_pty);
  881.   
  882.        savedrive = Dgetdrv();
  883.        Dgetpath(savedir, savedrive+1);
  884.        Dsetdrv(win->cwdir[0] - 'A');
  885.        Dsetpath(&win->cwdir[2]);
  886.  
  887.        if ((win->pid = Pexec(100, buffer.window_name, buffer.my_args,
  888.                        _base->p_env)) < 0) {
  889.      win->pid = NO_PID;
  890.          form_alert(1,"[0][Can not execute program ][Hmm]");
  891.        } else {
  892.          Fcntl(win->real_pty, &win->pid, TIOCSPGRP);
  893.          Psetpgrp(win->pid, win->pid);
  894.          Prenice(win->pid, -10);
  895.        }
  896.            
  897.        Dsetdrv(savedrive);
  898.        Dsetpath(savedir);
  899.  
  900.        Fforce(0, f0);
  901.        Fclose(f0);
  902.        Fforce(1, f1);
  903.        Fclose(f1);
  904.        Fforce(2, f2);
  905.        Fclose(f2);
  906.        Fforce(-1, fm1);
  907.        Fclose(fm1);
  908.      }
  909.    }
  910.  
  911. #ifdef DEBUG 
  912.   fprintf(stderr, "read_txt_win ends\n");
  913. #endif
  914. }
  915.